<?php $orgAccount = $this->Session->read('org_account'); ?>

<form class="form form-horizontal" method="post" action="<?php echo $this->Html->url(); ?>">

    <div class="row">

        <div class="col-lg-12 m-b-lg">
            <h4>Login credentials and accounts settings</h4>
            <p class="m-t-n-xs text-sm">
                Staff accounts are directly tied to member profiles. If a membership profile does not exist
                a new one will be created. Enter an email address to find an existing membership to link 
                account to.
            </p>
        </div>

        <div class="col-lg-11 m-b-lg col-lg-offset-1">

            <div class="form-group">
                <div class="col-lg-3 control-label">
                    Username / Email:
                </div>

                <div class="col-lg-9 controls form-inline">
                    <input type="email" name="OrganisationAccount[0][username]" id="username" class="form-control input-sm input-s" required="" value="<?php echo isset($account) ? $account['OrganisationAccount']['username'] : ''; ?>" />
                    <i class='availability fa'></i>
                    <input type='hidden' id='check_username_url' value='<?php echo $this->Html->url(array('action' => 'account', 'checkAvailability')); ?>' />
                </div>
            </div>

            <div class="form-group">
                <div class="col-lg-3 control-label">
                    Password:
                </div>

                <div class="col-lg-9 controls">
                        <?php if (isset($account)) { ?>
                    <a href="#" class="text-info">Reset</a>
                        <?php } else { ?>
                    <input type="password" class="form-control input-sm input-s" required="" name="OrganisationAccount[0][password]" value="" />
                        <?php } ?>
                </div>
            </div>

            <div class="form-group">
                <div class="col-lg-3 control-label">
                    Role:
                </div>

                <div class="col-lg-9 controls">
                    <select class="input-sm form-control input-s" name="OrganisationAccount[0][organisation_role_id]" required="">
                        <option value="">Choose</option>

                        <?php
                        foreach ($roles["OrganisationRole"] as $role) {
                            $key = $role['name'];
                            $value = $role['id'];
                            $selected = isset($account) && $value == $account['OrganisationAccount']['organisation_role_id'] ? "selected=selected" : "";
                            echo "<option value='$value' $selected>$key</option>";
                        }
                        ?>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <div class="col-lg-3 control-label">
                    Timezone:
                </div>

                <div class="col-lg-9 controls">
                    <select name="OrganisationAccount[0][timezone]" class="input-sm input-s">
                        <option value=""></option>

                        <?php
                        $timezones = $this->Timezone->timezones();
                        foreach ($timezones as $key => $value) {
                            $selected = isset($account) && $value == $account['OrganisationAccount']['timezone'] ? "selected" : "";
                            
                            if( !$selected && $value == 'UTC') {
                                $selected = "selected";
                            }
                            
                            echo "<option value='$value' $selected>$key</option>";
                        }
                        ?>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <div class="col-lg-3 control-label">
                    Notifications:
                </div>

                <div class="col-lg-9 controls">
                    <label class='switch'>
                        <input type='checkbox' name='OrganisationAccount[0][notifications]' value='1' <?php echo !isset($account) || $account['OrganisationAccount']['notifications'] == '1' ? 'checked' : ''; ?>  />
                        <span></span>
                    </label>
                </div>
            </div>

        </div>

        <div class="col-lg-12 m-b-lg clear">
            <h4>Profile Details</h4>
            <p class='m-t-n-xs text-sm'>Basic information for existing or new membership profile.</p>
        </div>

        <div class="col-lg-12">

            <div class="col-lg-8 col-lg-offset-1"> 
                <div class="form-group">
                    <div class="col-lg-4 control-label">
                        Name:
                    </div>

                    <div class="col-lg-8 controls form-inline">
                        <input type="text" class="form-control input-sm input-s-sm pf" id='first_name' name="Member[first_name]" placeholder="First Name" required="" value="<?php echo isset($account) ? $account['OrganisationAccount']['first_name'] : ''; ?>" />
                        <input type="text" class="form-control input-sm input-s-sm pf" id="last_name" name="Member[last_name]" placeholder="Last Name" required="" value="<?php echo isset($account) ? $account['OrganisationAccount']['last_name'] : ''; ?>" />
                    </div> 
                </div>

                <div class="form-group">
                    <div class="col-lg-4 control-label">
                        Gender:
                    </div>

                    <div class="col-lg-8 controls form-inline">
                        <select class="form-control input-sm input-s-sm pf" required="" id="gender" name='Member[gender]'>
                            <option value="">Select</option>
                            <?php $gender = isset($account) ? $account['OrganisationMember']['Member']['gender'] : ''; ?>
                            <option value="male" <?php echo $gender == 'male' ? 'selected' : ''; ?> >Male</option>
                            <option value="female" <?php echo $gender == 'female' ? 'selected' : ''; ?> >Female</option>
                        </select>
                    </div> 
                </div>

                <div class="form-group">
                    <div class="col-lg-4 control-label">
                        Birth Date:
                    </div>

                    <div class="col-lg-8 controls form-inline">
                        <input type="text" class="form-control datepicker-input input-sm input-s-sm pf" id="dob" name='Member[dob]' value='<?php echo isset($account) ? $account['OrganisationMember']['Member']['dob'] : ''; ?>' />
                    </div> 
                </div>

            </div>

            <!--div class="col-lg-3">
                <div class="text-center">
                    <a href="#" class="thumb-lg">
                        <img src="<?php echo $this->Html->url('/img/avatar_default.jpg'); ?>" class="img-circle img-thumbnail">
                    </a>

                    <div class="m-t-lg">

                        <button class="btn btn-xs btn-info"><i class='fa fa-upload'></i> Upload</button>
                    </div>
                </div>
            </div>-->
        </div>
    </div>

    <div class="row m-t-lg clear">
        <div class="col-lg-12">
            <div class="col-lg-3">
                &nbsp;
            </div>

            <div class="col-lg-9">
                <input type="hidden" name="OrganisationAccount[0][organisation_id]" value="<?php echo isset($account) ? $account['OrganisationAccount']['organisation_id'] : $orgAccount['Organisation']['id']; ?>" />
                <input type="hidden" name="OrganisationAccount[0][id]" value="<?php echo isset($account) ? $account['OrganisationAccount']['id'] : ''; ?>" />
                <input type="hidden" name="OrganisationMember[id]" value="<?php echo isset($account) ? $account['OrganisationMember']['id'] : ''; ?>" />
                <input type="hidden" name="OrganisationMember[organisation_id]" value="<?php echo isset($account) ? $account['OrganisationMember']['organisation_id'] : $orgAccount['Organisation']['id']; ?>" />
                <input type="hidden" name="OrganisationMember[member_id]" value="<?php echo isset($account) ? $account['OrganisationMember']['member_id'] : ''; ?>" />
                <input type="hidden" name="Member[id]" value="<?php echo isset($account) ? $account['OrganisationMember']['member_id'] : ''; ?>" />
                <input type="hidden" name="OrganisationAccount[0][active]" value="<?php echo isset($account) ? $account['OrganisationAccount']['active'] : '1'; ?>" />
                <input type="submit" id="save-btn" class="btn btn-sm btn-info" value="Save Change" />
                <input type="reset" id="cancel-btn" class="btn btn-sm btn-white" value="Cancel" />
            </div>
        </div>
    </div>
</form>